package com.zoshine.zzg.controller;

import com.github.pagehelper.PageInfo;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.pojo.OrderReceive;
import com.zoshine.zzg.pojo.OrderReceiveDetail;
import com.zoshine.zzg.pojo.PrisonerSettlement;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.OrderReceiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 收货单Controller
 * @author 田沛凌
 * @time 2017年6月28日 下午1:31:32
 */
@RestController
@RequestMapping(value = "orderReceive", method = RequestMethod.POST)
public class OrderReceiveController {

	private OrderReceiveService orderReceiveService;
	
	@Autowired
	public void setOrderReceiveService(OrderReceiveService orderReceiveService) {
		this.orderReceiveService = orderReceiveService;
	}

	/**
	 * 获取单个收货单
	 * @param id
	 */
	@RequestMapping("/getOrderReceive")
	public BaseResponse getOrderReceive(Long id){
		OrderReceive orderReceive = orderReceiveService.get(id);
		return new AppResponse(orderReceive);
	}
	/**
	 * 获取收货单集合
	 * @param orderReceive
	 */
	@RequestMapping("/pageOrderReceive")
	public BaseResponse pageOrderReceive(OrderReceive orderReceive){
		List<OrderReceive> pageList = orderReceiveService.list(orderReceive);
		return new AppResponse(new PageInfo<>(pageList));
	}
	/**
	 * 新增收货单
	 * @param orderReceive
	 */
	@RequestMapping("/addOrderReceive")
	public BaseResponse addOrderReceive(OrderReceive orderReceive){
	   /* List<IdAndCount> idAndCounts=new ArrayList<IdAndCount>();
	    orderReceive.setOrderSupplier(6515169651851264L);
	    IdAndCount idAndCount=new IdAndCount();
	    idAndCount.setGoodsId(6419241834119168L);
	    idAndCount.setGoodsCount(150);
	    idAndCounts.add(idAndCount);
	    IdAndCount idAndCount1=new IdAndCount();
        idAndCount1.setGoodsId(6417141574139904L);
        idAndCount1.setGoodsCount(50);
        idAndCounts.add(idAndCount1);
        orderReceive.setIdAndCounts(idAndCounts);*/
		orderReceiveService.add(orderReceive);
		return AppResponse.OK;
	}
	
	/**
	 * 修改收货单
	 * @param orderReceive
	 */
	@RequestMapping("/editOrderReceive")
	public BaseResponse editOrderReceive(OrderReceive orderReceive){
		orderReceiveService.edit(orderReceive);
		return AppResponse.OK;
	}
	
	/**
	 * 删除收货单
	 * @param id
	 */
	@RequestMapping("/delOrderReceive")
	public BaseResponse delOrderReceive(Long id){
		orderReceiveService.del(id);
		return  AppResponse.OK;
	}
	/**
     * 获取收货单详情集合
     * @param id
    */
    @RequestMapping("/pageOrderReceiveDetail")
    public BaseResponse pageOrderReceiveDetail(Long id){
        List<OrderReceiveDetail> pageList = orderReceiveService.pageOrderReceiveDetail(id);
        return new AppResponse(pageList);
    }
    /**
     * 结算数据JSON
     * @return
     */
    @RequestMapping("/pageSettlement")
    public BaseResponse pageSettlement(){
        List<PrisonerSettlement> pageList=new ArrayList<PrisonerSettlement>();
        PrisonerSettlement prisonerSettlement=new PrisonerSettlement();
        prisonerSettlement.setId(9854242458452L);
        prisonerSettlement.setPrisonerAccount(654875545521L);
        prisonerSettlement.setPrisonsAccount(654875485422L);
        prisonerSettlement.setSettlementMoney(12000);
        prisonerSettlement.setStatus(1);
        prisonerSettlement.setCreateTime(new Date());
        prisonerSettlement.setUpdateTime(new Date());
        pageList.add(prisonerSettlement);
        PrisonerSettlement prisonerSettlement1=new PrisonerSettlement();
        prisonerSettlement1.setId(6954785496545L);
        prisonerSettlement1.setPrisonerAccount(654875545521L);
        prisonerSettlement1.setPrisonsAccount(654875485422L);
        prisonerSettlement1.setSettlementMoney(45623);
        prisonerSettlement1.setStatus(2);
        prisonerSettlement1.setCreateTime(new Date());
        prisonerSettlement1.setUpdateTime(new Date());
        pageList.add(prisonerSettlement1);
        PrisonerSettlement prisonerSettlement2=new PrisonerSettlement();
        prisonerSettlement2.setId(79654342123L);
        prisonerSettlement2.setPrisonerAccount(654875545521L);
        prisonerSettlement2.setPrisonsAccount(654875485422L);
        prisonerSettlement2.setSettlementMoney(15872);
        prisonerSettlement2.setStatus(1);
        prisonerSettlement2.setCreateTime(new Date());
        prisonerSettlement2.setUpdateTime(new Date());
        pageList.add(prisonerSettlement2);
        return new AppResponse(new PageInfo<>(pageList));
    }
}
